package cn.edu.sgu.www.mhxysy.controller.change;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.entity.change.ChangeSorcery;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.change.ChangeSorceryService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "变化之术管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/change_sorcery", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChangeSorceryController {

    private final ChangeSorceryService changeSorceryService;

    @Autowired
    public ChangeSorceryController(ChangeSorceryService changeSorceryService) {
        this.changeSorceryService = changeSorceryService;
    }

    @ApiOperation("查询全部变化之术")
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    public JsonResult<List<ChangeSorcery>> selectAll() {
        List<ChangeSorcery> list = changeSorceryService.selectAll();

        return JsonResult.success(null, list);
    }

    @ApiOperation("通过ID查询变化之术")
    @RequestMapping(value = "/selectById", method = RequestMethod.GET)
    public JsonResult<ChangeSorcery> selectById(
            @ApiParam(name = "id", value = "变化之术ID", required = true)
            @NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
        ChangeSorcery changeSorcery = changeSorceryService.selectById(id);

        return JsonResult.success(null, changeSorcery);
    }

}